import { createRouter, createWebHashHistory, RouterView } from 'vue-router'
import authGuard from './authGuard';



const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  scrollBehavior: () => ({ top: 0 }),
  routes: [
    {
      path: '/',
      component: () => import("@/components/XtxLayout.vue"),
      children: [
        {
          path: "/",
          component: () => import("@/views/home/HomePage.vue")
        },
        {
          path: "category/:id",
          component: () => import("@/views/category/ToCategoryPage.vue")
        },
        {
          path: "category/:sub/:top/:sub",
          component: () => import("@/views/category/SubCategoryPage.vue")
        },
        {
          path: "goods/:id",
          component: () => import("@/views/goods/GoodsDetailPage.vue"),
        },
        {
          path: "cart",
          component: () => import("@/views/cart/CartPage.vue"),
        },
        {
          path: "checkout/order",
          component: () => import("@/views/pay/checkoutPage.vue")
        },
        {
          path: "checkout/pay",
          component: () => import("@/views/pay/payPage.vue")
        },
        {
          path: "pay/callback",
          component: () => import("@/views/pay/PayResultPage.vue")
        },
        {
          path: "member",
          component: () => import("@/components/XtxMemberLayout.vue"),
          redirect: "/member/home",
          children: [
            {
              path: "home",
              component: () => import("@/views/member/home/MemberHomePage.vue")
            },
            {
              path: "order",
              component: h(RouterView),
              children: [
                {
                  path: "",
                  component: () =>
                    import("@/views/member/order/OrderListPage.vue"),
                },
                {
                  path: ":id",
                  component: () =>
                    import("@/views/member/order/OrderDetailPage.vue"),
                },
              ]
            },
          ]
        }
      ]
    },
    {
      path: '/login',
      component: () => import("@/views/login/components/LoginPage.vue")

    },
    {
      path: "/login/callback",
      component: () => import("@/views/login/QQLoginBack.vue"),
      beforeEnter: () => {
        //如果没有进行QQ扫码授权
        if (!window.QC.Login.check()) {
          //不能进入该页面
          return false;
        }
      }
    },


  ]
})
router.beforeEach(authGuard)
export default router
